<template>
  <div class="app-container">
    <div class="head">
      <img src="@/assets/img/Layout/position.png" />
      <p class="see-block">调拨单详情</p>
    </div>
    <div class="view-container">
      <el-row class="status-title">
        <el-col class="mr20 width100" v-if="detailData.status == '1' || detailData.status == '3'">
          <el-button
            class="btn-default width100"
            type="primary"
            @click="audit()"
            v-hasPermi="['system:transferOrder:approve']"
          >审核</el-button>
        </el-col>
        <el-col :span="10" class="status-container">
          <div class="status-item">
            <span :class="{ 'active' : detailData.status == 0 }">待提交</span>
            <span :class="{ 'active' : detailData.status == 1 }">待审核</span>
            <span :class="{ 'active' : detailData.status == 2 }">已完成</span>
            <span :class="{ 'active' : detailData.status == 3 }">拒绝</span>
          </div>
        </el-col>
      </el-row>
      <el-row class="detail-item">
        <el-col :span="8">
          <span>单据编码：</span>{{ detailData.code ?  detailData.code : '暂无'}}
        </el-col>
        <el-col :span="8">
          <span>业务日期：</span>{{ detailData.businessDate ?  detailData.businessDate : '暂无'}}
        </el-col>
      </el-row>
      <el-row class="detail-item">
        <el-col :span="8">
          <span>调出公司：</span>{{ detailData.outCompanyName ?  detailData.outCompanyName : '暂无'}}
        </el-col>
        <el-col :span="8">
          <span>调出部门：</span>{{ detailData.outCompanyDept ?  detailData.outCompanyDept : '暂无'}}
        </el-col>
        <el-col :span="8">
          <span>调出仓库：</span>{{ detailData.outWarehouseName ?  detailData.outWarehouseName : '暂无'}}
        </el-col>
      </el-row>
      <el-row class="detail-item">
        <el-col :span="8">
          <span>调入公司：</span>{{ detailData.inCompanyName ?  detailData.inCompanyName : '暂无'}}
        </el-col>
        <el-col :span="8">
          <span>调入部门：</span>{{ detailData.inCompanyDept ?  detailData.inCompanyDept : '暂无'}}
        </el-col>
        <el-col :span="8">
          <span>调入仓库：</span>{{ detailData.inWarehouseName ?  detailData.inWarehouseName : '暂无'}}
        </el-col>
      </el-row>
      <el-row class="detail-item">
        <el-col :span="16">
          <span>调拨原因：</span>{{ detailData.transferReason ?  detailData.transferReason : '暂无'}}
        </el-col>
      </el-row>
      <el-row class="detail-item">
        <el-col :span="24">
          <el-table :data="detailData.detailList">
            <el-table-column label="序号" type="index" align="center" width="50" />
            <el-table-column :label="item.label" :prop="item.prop" :width="item.width" v-for="(item, index) in columns" :key="index" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row[item.prop] }}</span>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <el-row class="detail-item">
        <el-col :span="8">
          <span>合计数量：</span>{{ detailData.total ?  detailData.total : '暂无'}}
        </el-col>
      </el-row>
    </div>
    <!-- 审核/反审核 -->
    <el-dialog :visible.sync="open" width="500" top="100px" append-to-body title="审核意见" center>
      <el-row>
        <el-col :span="24">
          <textarea
            class="approve-textarea"
            v-model="approveRemark"
            type="textarea"
            placeholder="请输入意见和看法"
          >
          </textarea>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          class="btn-success mr20 width100"
          @click="agreeApprove()"
        >同意</el-button>
        <el-button
          type="primary"
          class="btn-cancel width100"
          @click="disagreeApprove()"
        >拒绝</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { transferOrderDetail, transferOrderApprove } from "@/api/system/transferOrder/transferOrder"
export default {
  name: "detail",
  data(){
    return {
      columns: [{
        prop: "specificationCode",
        label: "货品编码",
      },{
        prop: "specificationName",
        label: "货品名称",
      },{
        prop: "specification",
        label: "规格",
      },{
        prop: "unit",
        label: "单位",
      },{
        prop: "transferNum",
        label: "调拨数量",
      },{
        prop: "remark",
        label: "备注",
      }],
      id: '',
      detailData: '',
      open: false,
      approveRemark: '',
    }
  },
  created() {
    this.id = this.$route.query.id
    this.getDetailData()
  },
  methods: {
    // 获取详细信息
    getDetailData(){
      transferOrderDetail(this.id).then(res => {
        this.detailData = res.data
      })
    },
    // 审核
    audit(){
      this.open = true
    },
    agreeApprove(){
      transferOrderApprove({id: this.id, status: 2, approveRemark: this.approveRemark}).then(res => {
        if(res.code == 200){
          this.$tab.closeOpenPage({ path: "/warehouseManagement/warehouse/transferOrder" })
          this.open = false
          this.$modal.msgSuccess("操作成功")
        }
      })
    },
    disagreeApprove(){
      transferOrderApprove({id: this.id, status: 3, approveRemark: this.approveRemark}).then(res => {
          if(res.code == 200){
            this.$tab.closeOpenPage({ path: "/warehouseManagement/warehouse/transferOrder" })
            this.open = false
            this.$modal.msgSuccess("操作成功")
          }
      })
    },
  }
}
</script>